package zzps.exeed.web.handle;

import zzps.exeed.web.Context;

import java.util.List;

public class FilterChainImpl implements FilterChain{

    private final Handler handler;
    private final List<Filter> filters;
    private int index = 0;

    public FilterChainImpl(Handler handler, List<Filter> filters) {
//        this.context = context;
        this.handler = handler;
        this.filters = filters;
    }

    @Override
    public void doFilter(Context context) throws Throwable {
        index++;
        if (index >= filters.size()){
            handler.handle(context);
        }else {
            filters.get(index).doFilter(context,this);
        }
    }
}
